{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4421b9c8",
   "metadata": {},
   "source": [
    "-----\n",
    "* 本周知识点：图像识别（人脸识别）\n",
    "* week04\n",
    "* liyi的笔记\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79347aa5",
   "metadata": {},
   "source": [
    "# 上周内容\n",
    "\n",
    "> 1. API文档阅读(考试)\n",
    "> 2. requests模块(考试)\n",
    "> 3. 百度通用人脸识别\n",
    "\n",
    "# 本周内容\n",
    "\n",
    "## 1. 人脸识别概念和基础\n",
    "## 2. 人脸识别应用\n",
    "## 3. 人脸识别实践-face++\n",
    "> 1. 人脸检测\n",
    "> 2. 人脸比对+人脸搜索\n",
    ">> 1. 人脸集合创建\n",
    ">> 2. 人脸"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77c35ad9",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础\n",
    "\n",
    "[知智1分钟人脸识别](https://zhuanlan.zhihu.com/p/36262110)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c1580005",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678715429,3251c929-db2c-4f65-9e5e-b61f3425df41', 'time_used': 94, 'faces': [{'face_token': '0b1de3e08a301eee650aa69e8fb82b4d', 'face_rectangle': {'top': 184, 'left': 115, 'width': 70, 'height': 70}}], 'image_id': 'NEHIr9t8G7ngvKa3YkEH2g==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('OIP-C.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload={\n",
    "    'api_key':'uezqfilIz1D-NAfJ1ZA5MRMLNE1Qypxi',\n",
    "    'api_secret':'RLVG_KsWxBmx9BdH9TXiV43vbCjxMsfR',\n",
    "    'image_base64':img\n",
    "    \n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4ed532f0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678715430,68cf8c35-8d8f-4bed-ab26-0e3cab5da5a8', 'time_used': 127, 'faces': [{'face_token': 'ad3b47b8148f95a06f3e47ba1adb6efb', 'face_rectangle': {'top': 184, 'left': 115, 'width': 70, 'height': 70}, 'attributes': {'gender': {'value': 'Female'}, 'age': {'value': 26}, 'smile': {'value': 1.047, 'threshold': 50.0}, 'headpose': {'pitch_angle': -3.0955143, 'roll_angle': 8.167151, 'yaw_angle': 64.406975}, 'blur': {'blurness': {'value': 79.666, 'threshold': 50.0}, 'motionblur': {'value': 79.666, 'threshold': 50.0}, 'gaussianblur': {'value': 79.666, 'threshold': 50.0}}, 'emotion': {'anger': 0.044, 'disgust': 0.112, 'fear': 0.024, 'happiness': 0.71, 'neutral': 81.72, 'sadness': 0.024, 'surprise': 17.365}, 'facequality': {'value': 0.006, 'threshold': 70.1}, 'beauty': {'male_score': 67.488, 'female_score': 68.88}, 'mouthstatus': {'surgical_mask_or_respirator': 0.0, 'other_occlusion': 0.002, 'close': 95.905, 'open': 4.093}}}], 'image_id': 'NEHIr9t8G7ngvKa3YkEH2g==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('OIP-C.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload = {\n",
    "    'api_key':'uezqfilIz1D-NAfJ1ZA5MRMLNE1Qypxi',\n",
    "    'api_secret':'RLVG_KsWxBmx9BdH9TXiV43vbCjxMsfR',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty,mouthstatus'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f92d8404",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "258.237px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
